<template>
    <Button class="action-button" :disabled="!buttonEnable" :loading="fetching || posting" @click="buttonClick">
        <icon v-if="model.icon && !fetching && !posting" :type="model.icon"></icon>{{model.name}}
    </Button>
</template>
<script>
export default {
  subModuleStore: true,
  computed: {
    buttonEnable() {
      if (this.enable === false) {
        return false;
      } else {
        return this.scopeEnable && !this.getting && !this.gettingError;
      }
    }
  },
  methods: {
    buttonClick() {
      if (this.needSelect && this.onwerSelectedCount < 1) {
        return this.$Message.warning(`请选择数据进行 ${this.model.name} 操作`);
      }
      if (this.needSelectOne && this.onwerSelectedCount !== 1) {
        return this.$Message.warning(`请选择单一数据进行 ${this.model.name} 操作`);
      }
      this.actionCall(this.onwerSelectedData);
    }
  }
};
</script>

<style lang="less">
.action-button {
  .ivu-icon {
    margin-right: 6px;
  }
}
</style>
